package cn.segment.core.seg;

/**
 * 前导初分词
 * 
 * @author Huang Yue
 * @version 创建时间：2010-6-9 上午10:55:26
 */
public class SufSeg extends SegBasic
{
    public SufSeg() {
        super();
    }

    /**
     * 前导对句子分词具体方法
     */
    protected void lineSeg(WordTeam segResult, String str, int index)
    {
        if (str == null || str.equals(""))
        {
            return;
        }
        StringBuffer sb = new StringBuffer(str);

        for (int i = 0; i < index; i++)
        {
            if (dict.contains(sb.toString()))
            {
                segResult.addWord(sb.toString());
                str = str.substring(0, i);
                segResult.addScore(Math.log10(sb.length() * CONST_WORD));
                lineSeg(segResult, str, str.length() - 1);
                break;
            }
            sb.delete(0, 1);
        }

        if (sb.length() == 1)
        {
            segResult.addWord(sb.toString());
            str = str.substring(0, index);
            segResult.addScore(Math.log10(CONST_CHAR));
            lineSeg(segResult, str, str.length() - 1);
        }
    }
}
